<template>
<div>
  <div>
    <h1>登录</h1>
    <el-input v-model="params.username" placeholder="请输入账号" style="width: 350px"></el-input><br>
    <br>
    <el-input v-model="params.password" placeholder="请输入密码" show-password style="width: 350px"></el-input><br>
    <br>
    <el-button @click="this.$router.push('/')">点击返回</el-button>
    <el-button type="primary" icon="el-icon-position" round @click="login()" style="width: 200px">点击登录</el-button>
    <span style="color: #409EFF" @click="zhuce()">没有账号？点击注册账号</span>
  </div>
</div>
</template>

<script>

export default {
  name: "Login",
  created() {

  },
  data(){
    return{
      params:{username:"",password:"", grant_type: 'password', client_id: 'bbb', client_secret: 111}
    }
  },
  methods:{
    login(){
      this.$http.post("authserver/oauth/token",this.params).then(data=>{
        if (data.data.access_token!=null){
          alert("登录成功")
          //把token值存到session中
          sessionStorage.setItem('token',this.$qs.stringify(data.data))
          //把用户的uid存在store中
          this.$store.commit('setUser',data.data.uid)
          //把刷新token的值存入state
          this.$store.commit("setClient",this.params)
          this.$router.push("/")
        }else {
          alert("登录失败")
        }
      })
      },
      zhuce(){
      alert("去注册")
        this.$router.push("/register")
      }
    }
}
</script>

<style scoped>

</style>
